package com.feng.springmvc.controller;

import com.feng.springmvc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class UserController {

    //http://localhost:8083/user/u1?name=feng今天
    @GetMapping("/u1")
    public String test1(String name, Model model){
        //1.接收前端参数
        model.addAttribute("msg",name);
        //2.将结果返回前端
        return "test";
    }

    //http://localhost:8083/user/u2?username=feng今天
    @GetMapping("/u2")
    public String test2(@RequestParam("username") String name, Model model){
        //1.接收前端参数
        System.out.println(name);
        model.addAttribute("msg",name);
        //2.将结果返回前端
        return "test";
    }

    //http://localhost:8083/user/u3?name=feng今天&id=101&age=18
    //User(id=101, name=feng今天, age=18)
    @GetMapping("/u3")
    public String test3(User user, Model model){
        //1.接收前端参数
        System.out.println(user);
        model.addAttribute("msg",user);
        //2.将结果返回前端
        return "test";
    }
}
